﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace pictureAnalyse
{
    public partial class Form_ColorViewer : Form
    {
        private PictureColors picColor;
        private float[] Values;         // 选择的颜色值

        public Form_ColorViewer()
        {
            InitializeComponent();
        }

        private void Form_DragEnter(object sender, DragEventArgs e)
        {
            FileDrag.dragEnter(e);
        }

        private void Form_DragDrop(object sender, DragEventArgs e)
        {
            String paths = FileDrag.dragDrop(e);
            String[] files = paths.Split(';');
            if (files == null || files.Length == 0) return;

            String picPath = files[0];     // 获取第一个图像

            label_path.Text = "当前图像:" + Path.GetFileName(picPath);
            ShowColorInfo(picPath);         // 显示色值分布信息
        }

        /// <summary>
        /// 显示图像颜色值分布信息逻辑
        /// </summary>
        private void ShowColorInfo(String picPath)
        {
            picColor = new PictureColors(picPath);  // 载入图像颜色值统计信息
            button_Click(button_C, null);
        }

        /// <summary>
        /// 显示各颜色分量的统计信息
        /// </summary>
        private void button_Click(object sender, EventArgs e)
        {
            bool isAve = checkBox_Ave.Checked;

            if (chartBox_Color != null)
            {
                Button button = sender as Button;

                if (button == button_C) Values = picColor.C;
                else if (button == button_A) Values = picColor.A;
                else if (button == button_R) Values = picColor.R;
                else if (button == button_G) Values = picColor.G;
                else if (button == button_B) Values = picColor.B;
                

                if (isAve) chartBox_Color.Values = ValueAnalyser.getAverage(Values);
                else chartBox_Color.Values = Values;
            }
        }

    }
}
